package com.app.freshmenapp.controller;

import com.app.freshmenapp.entity.Prompts;
import com.app.freshmenapp.service.PromptsService;
import com.app.freshmenapp.tools.FunctionExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Auther: Administrator
 * @Date: 2019.07.20 17:42
 * @Description:
 */
@RestController
@RequestMapping(value = "/prompts")
public class PromptsController {

    @Autowired
    private PromptsService promptsService;

    @Autowired
    private FunctionExample functionExample;

    @RequestMapping(value = "/list")
    public Map<String,Object> findAll(){
        List<Prompts> list=promptsService.findAllPrompts();
        Map<String,Object> map=new HashMap<>();
        map.put("success",true);
        map.put("msg","成功");
        map.put("list",list);
        return map;
    }

    @RequestMapping(value = "/findone/{id}")
    public Map<String,Object> findPrompts(@PathVariable int id){
        Prompts prompts=promptsService.findById(id);
        return functionExample.findOne(prompts);
    }

    @RequestMapping(value = "/deleteone/{id}",method = RequestMethod.DELETE)
    public Map<String,Object> deletePrompts(@PathVariable int id){
        boolean judge=promptsService.deletePrompts(id);
        return functionExample.otherOne(judge);
    }


    @RequestMapping(value = "/updateone",method = RequestMethod.PUT)
    public Map<String,Object> updatePrompts(@RequestBody Prompts prompts){
        boolean judge=promptsService.updatePrompts(prompts);
        return functionExample.otherOne(judge);
    }

    @RequestMapping(value = "/addone" ,method =RequestMethod.POST)
    public Map<String,Object> addPrompts(@RequestBody Prompts prompts){
        boolean judge=promptsService.addPrompts(prompts);
        return functionExample.otherOne(judge);
    }

}
